#!/usr/bin/env python
# coding: utf-8

from __future__ import print_function
import timeit, random


class Stack:
    """
    Simple stack implementation
    """
    def __init__(self, seq=[]):
        self.data = [x for x in seq]

    def push(self, x):
        self.data.append(x)

    def pop(self):
        return self.data.pop()

    def peek(self):
        return self.data[-1]

    def is_empty(self):
        return len(self.data) == 0

    def size(self):
        return len(self.data)


def par_check(s, verbose=False):
    stck = Stack([])
    op = '([{<'  # can also use dictionaries, tho they're slower
    cl = ')]}>'
    for p in s:
        if p in op:
            stck.push(p)
        elif p in cl:
            if stck.is_empty() or stck.pop() != op[cl.index(p)]:
                if verbose: print('incorrect sequence "{}"'.format(s))
                return False
    if stck.is_empty():
        if verbose: print('success "{}"'.format(s))
        return True
    else:
        if verbose: print('incorrect sequence "{}"'.format(s))
        return False


def RPN(args):
    args = args.split()
    st = Stack()
    for r1 in args:
        if r1.isdigit():
            st.push(r1)
        else:
            st.push(RPN_eval(r1, st.pop(), st.pop()))

def RPN_eval(op, y, x):
    if op == '+':
        return x + y
    if op == '-':
        return x - y
    if op == '*':
        return x * y
    if op == '/':
        return x / y
